<!---
	Copyright 2010 Edward Trudeau, Jeremy Battle
    This software is freely available under the MIT License: http://www.opensource.org/licenses/mit-license.php
    http://ayc.googlecode.com
    
--->

<cfcomponent name="ValidationService" output="false">

	<cffunction name="init" access="public" output="false" returntype="ValidationService">
		<cfargument name="ValidationDAO" type="ValidationDAO" required="true" />
		<cfargument name="ValidationGateway" type="ValidationGateway" required="true" />

		<cfset variables.ValidationDAO = arguments.ValidationDAO />
		<cfset variables.ValidationGateway = arguments.ValidationGateway />

		<cfreturn this/>
	</cffunction>

	<cffunction name="createValidation" access="public" output="false" returntype="Validation">
		<cfargument name="ValidationId" type="numeric" required="true" />
		<cfargument name="FieldId" type="numeric" required="false" />
		<cfargument name="ValidateRule" type="string" required="false" />
		<cfargument name="ValidationVal" type="string" required="false" />
		<cfargument name="ValidationMsg" type="string" required="false" />
		
			
		<cfset var ValidationBean = createObject("component","Validation").init(argumentCollection=arguments) />
		<cfreturn ValidationBean />
	</cffunction>

	<cffunction name="getValidation" access="public" output="false" returntype="Validation">
		<cfargument name="ValidationId" type="numeric" required="true" />
		
		<cfset var Validation = createValidation(argumentCollection=arguments) />
		<cfset variables.ValidationDAO.read(Validation) />
		<cfreturn Validation />
	</cffunction>

	<cffunction name="getValidations" access="public" output="false" returntype="array">
		<cfargument name="ValidationId" type="numeric" required="false" />
		<cfargument name="FieldId" type="numeric" required="false" />
		<cfargument name="ValidateRule" type="string" required="false" />
		<cfargument name="ValidationVal" type="string" required="false" />
		<cfargument name="ValidationMsg" type="string" required="false" />
		
		<cfreturn variables.ValidationGateway.getByAttributes(argumentCollection=arguments) />
	</cffunction>

	<cffunction name="saveValidation" access="public" output="false" returntype="struct">
		<cfargument name="Validation" type="Validation" required="true" />

		<cfreturn variables.ValidationDAO.save(Validation) />
	</cffunction>

	<cffunction name="deleteValidation" access="public" output="false" returntype="struct">
		<cfargument name="ValidationId" type="numeric" required="true" />
		
		<cfset var Validation = createValidation(argumentCollection=arguments) />
		<cfreturn variables.ValidationDAO.delete(Validation) />
	</cffunction>
</cfcomponent>


